package mscs.data;

import java.util.ArrayList;

public class Operations {
	private ArrayList<Operation> operations = new ArrayList<Operation>();
	public Operations() {
		this.operations = getOldOperations().getOperations();
	}
	public void addOperation(Operation operation) {
		operations.add(operation);
	}
	public ArrayList<Goods> getGoodsCollection(Goods goods) {//获得当前货物的List
		ArrayList<Goods> goodsList = new ArrayList<Goods>();
		for(Operation operation : operations)
			for(Goods goodsItr : operation.getGoodsList())
				if(goodsItr.getId() == goods.getId())
					goodsList.add(goodsItr);
		return goodsList;
	}
	public int getSum(Goods goods) {//获得当前货物的总量
		int sum = 0;
		for(Operation operation : operations)
			for(Goods goodsItr : operation.getGoodsList())
				if(goodsItr.getId() == goods.getId())
					sum++;
		return sum;
	}
	public int getPreSum(Goods goods) {//获得指定货物入库前的总量
		ArrayList<Goods> goodsList = getGoodsCollection(goods);
		goodsList.remove(goodsList.size() - 1);
		int sum = 0;
		for(Goods goodsItr : goodsList)
			sum += goodsItr.getNum();
		return sum;
	}
		
	public void save() {
		//将对象保存到文件中
	}
	public Operations getOldOperations() {
		return new Operations();//从文件中取得Operations对象
	}

	public ArrayList<Operation> getOperations() {
		return operations;
	}
}
